package util

import (
	"encoding/json"
	"github.com/sirupsen/logrus"
	"gofile/src/vo"
	"net/http"
)

func ProcessResult(result interface{}, err error, w http.ResponseWriter) {
	var cmdResult vo.CmdResult
	if err != nil {
		//panic(err)
		logrus.Error("错误:" + err.Error())
		cmdResult.Success = false
		cmdResult.ErrorMsg = err.Error()
	} else {
		cmdResult.Success = true
	}
	//logrus.Info("提示信息:", result)
	cmdResult.Data = result

	//p := &Product{}
	//err := json.Unmarshal([]byte(result), p)

	sysJson, _ := json.Marshal(cmdResult)

	jsonInfo := string(sysJson)

	cmdResult.Data = jsonInfo

	w.Write(sysJson)

}
